<?php

namespace Mlym\CodeGeneration\ControllerGeneration\Method;

class GetSelectPage extends MethodAbstract
{

    protected $methodName = 'getSelectPage';
    protected $methodDescription = '获取Select列表';
    protected $methodAllow = 'GET';


    function addMethodBody()
    {
        $method = $this->method;
        $modelName = $this->getModelName();
        /**
         * Page注解
         */
        $method->addComment("@Param(name=\"pageNo\", from={GET}, alias=\"页数\", optional=\"\", integer=\"\", defaultValue=\"1\")");
        $method->addComment("@Param(name=\"pageSize\", from={GET}, alias=\"每页总数\", optional=\"\", integer=\"\", defaultValue=\"20\")");

        $methodBody = <<<Body
\$param = ContextManager::getInstance()->get('param');
\$pageNo = (int)(\$param['pageNo'] ?? 1);
\$pageSize = (int)(\$param['pageSize'] ?? 20);
\$model = new {$modelName}();
\$data = \$model->getSelectPage(\$pageNo, \$pageSize);
\$this->writeJson(Status::CODE_OK, \$data, '操作成功');
Body;
        $method->setBody($methodBody);
    }

    function addComment()
    {
        $this->method->addComment("@throws \Throwable");
    }
}
